package com.ruoyi.test.controller;

import java.util.Map;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;

import javax.servlet.http.HttpServletResponse;

import com.mashuai.utils.base.MsAssertUtils;
import com.ruoyi.system.ms.constant.SysParamsConstant;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test.domain.PcjItem;
import com.ruoyi.test.service.IPcjItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品档案Controller
 *
 * @author ruoyi
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/test/pcjItem")
public class PcjItemController extends BaseController {
    @Autowired
    private IPcjItemService pcjItemService;

    /**
     * 查询物品档案列表-分页
     */
    //@PreAuthorize("@ss.hasPermi('test:pcjItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        IPage<PcjItem> page = pcjItemService.selectPcjItemPage(params);
        return getDataTableMp(page);
    }

    /**
     * 多表关联查询，主要为测试数据权限
     */
    @PostMapping("/listMore")
    public TableDataInfo listMore() {
        IPage<PcjItem> page = pcjItemService.selectListMore();
        return getDataTableMp(page);
    }
    /**
     * 导出物品档案列表
     */
    @PreAuthorize("@ss.hasPermi('test:pcjItem:export')")
    @Log(title = "物品档案" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        IPage<PcjItem> page = pcjItemService.selectPcjItemPage(params);
        ExcelUtil<PcjItem> util = new ExcelUtil<PcjItem>(PcjItem.class);
        util.exportExcel(response, page.getRecords(), "物品档案数据");
    }

    /**
     * 获取物品档案详细信息-根据主键查询
     */
    @PreAuthorize("@ss.hasPermi('test:pcjItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pcjItemService.selectPcjItemById(id));
    }

    /**
     * 新增物品档案
     */
    @PreAuthorize("@ss.hasPermi('test:pcjItem:add')")
    @Log(title = "物品档案" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcjItem pcjItem) {
        return toAjax(pcjItemService.insertPcjItem(pcjItem));
    }

    /**
     * 修改物品档案
     */
    @PreAuthorize("@ss.hasPermi('test:pcjItem:edit')")
    @Log(title = "物品档案" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcjItem pcjItem) {
        return toAjax(pcjItemService.updatePcjItem(pcjItem));
    }

    /**
     * 删除物品档案
     */
    @PreAuthorize("@ss.hasPermi('test:pcjItem:remove')")
    @Log(title = "物品档案" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pcjItemService.deletePcjItemByIds(ids));
    }
}
